/*
 * Copyright 2008 Federal Emergency Management Agency
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0 
 *    
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 *  
 */
package gov.fema.hazus.bdc.client.general;

import gov.fema.hazus.bdc.client.common.ui.AbstractWidget;
import gov.fema.hazus.bdc.client.common.ui.InCASTTabPanel;
import gov.fema.hazus.bdc.client.general.building.GeneralBuildingForm;
import gov.fema.hazus.bdc.client.general.capacity.CapacityForm;
import gov.fema.hazus.bdc.client.general.economic.EconomicForm;
import gov.fema.hazus.bdc.client.general.identification.IdentificationForm;
import gov.fema.hazus.bdc.client.general.location.LocationForm;
import gov.fema.hazus.bdc.shared.entity.Building;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.DockPanel;

public class GeneralWidget extends AbstractWidget {

	private DockPanel docker;
	private InCASTTabPanel tabPanel;

	private IdentificationForm identificationForm;
	private LocationForm locationForm;
	private GeneralBuildingForm buildingForm;
	private EconomicForm economicForm;
	private CapacityForm capacityForm;
	
	// constants
	private GeneralConstants constants;
	
	
	public GeneralWidget(Building building)
	{
		
		// constants
		constants = (GeneralConstants)GWT.create(GeneralConstants.class);
		
		docker = new DockPanel();
		
		// set up forms
		identificationForm = new IdentificationForm(building);
		identificationForm.setStyleName("building-detail-form");
		locationForm = new LocationForm(building);
		locationForm.setStyleName("building-detail-form");
		buildingForm = new GeneralBuildingForm(building);
		buildingForm.setStyleName("building-detail-form");
		economicForm = new EconomicForm(building);
		economicForm.setStyleName("building-detail-form");
		capacityForm = new CapacityForm(building);
		capacityForm.setStyleName("building-detail-form");
		
		// set up a tab panel
		tabPanel = new InCASTTabPanel();
		//tabPanel.setWidth("100%");
		tabPanel.setStyleName("debug-outline");
		
		// add forms		
		tabPanel.add(identificationForm, identificationForm.getTabTitle() );
		tabPanel.add(locationForm, locationForm.getTabTitle() );
		tabPanel.add(buildingForm, buildingForm.getTabTitle() );
		tabPanel.add(economicForm, economicForm.getTabTitle() );
		tabPanel.add(capacityForm, capacityForm.getTabTitle() );
		//tabPanel.addTabListener(new UrchinTabListener());
		
		// default
		tabPanel.selectTab(0);
		
		// add tabs to docker
		docker.add(tabPanel, DockPanel.CENTER);
		
		// add a style to the sub tabs
		tabPanel.setStyleName("emcode-subnav-tabbar");
		
		
		initWidget(docker);
		
		
	}
	
	public void updateBuilding(Building building)
	{
		identificationForm.updateBuilding(building);
		locationForm.updateBuilding(building);
		buildingForm.updateBuilding(building);
		economicForm.updateBuilding(building);
		capacityForm.updateBuilding(building);
	}

	public void resetTabs() {
		tabPanel.selectTab(0);
	}

	public void updateName() {
		identificationForm.updateName();
	}

	public void updateLatLng(double latitude, double longitude) {
		GWT.log("Sending lat/lng to locationForm.updateLatLng()", null);
		locationForm.updateLatLng(latitude, longitude);
	}
	
}
